package controllers;

import beans.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import services.impl.LogServicesImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/log")
public class LogController {

    @Autowired
    private LogServicesImpl lsi;

    @RequestMapping("/log")
    public List log(){
        List<Log> list = lsi.selectList();
        return list;
    }

    @RequestMapping("/createlog")
    public String createLog(@RequestBody Log log){
        lsi.insertSelective(log);
        return null;
    }

    @RequestMapping("/editlog")
    public String editLog(@RequestBody Log log){
        lsi.updateByPrimaryKeySelective(log);
        return null;
    }

    @RequestMapping("/detailslog")
    public Log detailsLog(HttpServletRequest request){
        int i = Integer.parseInt(request.getParameter("organId"));
        Log log = lsi.selectByPrimaryKey(i);
        return log;
    }

    @RequestMapping("/searchlog")
    public List<Log> searchLog(@RequestBody Map<String,String> request){
        String select = request.get("selectText");
        String input = request.get("inputText");
        List<Log> list = lsi.selectSelective(select,input);
        return list;
    }

    @RequestMapping("/deletelog")
    public String deleteLog(HttpServletRequest request){
        int i = Integer.parseInt(request.getParameter("organId"));
        lsi.deleteByPrimaryKey(i);
        return null;
    }
}
